"use strict";
/* Controllers */
app.controller("dimDefineAddController", ['$scope', '$q', '$location', '$rootScope', '$routeParams', 'dimDefineAddService', function ($scope, $q, $location, $rootScope, $routeParams, dimDefineAddService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id; // 如果id!=0为更新

    vm.p.typeDesc = '-';
    vm.p.itemDesc = '-';

    var errorFn = function (result) {
        alert(result);
    };

    $scope.setDimDefine = function () {
        var vm = $scope.vm;
        var params = vm.p;
        var procFn = function (response) {
            if (response.success && response.data) {
                alert("执行成功！")
            } else {
                alert(response.msg);
            }
        };
        return dimDefineAddService.setDimDefine(params, procFn, errorFn);
    };


    $scope.getDimDefine = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id
        };
        var procFn = function (res) {
            if (res.success && res.data) {
                vm.p = res.data;
            } else {
                alert(res.msg);
            }
        };
        return dimDefineAddService.getDimDefine(params, procFn, errorFn);
    };

    if (vm.p.id != 0) {
        console.log(vm.p.id);
        $scope.getDimDefine()
    }
}]);


/* Services */
app.service('dimDefineAddService', ['ajaxService', function (ajaxService) {

    this.getDimDefine = function (params, successFunction, errorFunction) {
        return ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dim_define/getDimDefine.do", successFunction, errorFunction);
    };

    this.setDimDefine = function (params, successFunction, errorFunction) {
        return ajaxService.AjaxPost(params, "/star/api/basic-service/v1/dim_define/setDimDefine.do", successFunction, errorFunction);
    };

}]);